<body>
  响应式练习：<br />
  let a = 10;<br />
  let b = a * 10;<br />
  题目： 保持 b永远是a得十倍 <br />

</body>

<script>
  // 依赖跟踪
  var activeEffect;
  class Dep {

    constructor(value) {
      this.subscribers = []
      this._value = value;
    }

    get value() {
      this.depend();
      return this._value
    }

    set value(newValue) {
      this._value = newValue;
      this.notify();
    }

    depend() {
      if (activeEffect) {
        this.subscribers.push(activeEffect);
      }
    }
    notify() {
      this.subscribers.forEach(sub => {
        sub(this.value)
      })
    }
  }

  // 副作用函数
  function watchEffect(effect) {
    activeEffect = effect
    effect()
    activeEffect = null
  }
  var dep = new Dep("hello");

  watchEffect(() => {
    console.log(dep.value);
  })

  dep.value = "change"
</script>